package com.dragon.refect.error;

/**
 * 创建线程导致内存溢出异常
 *
 * @author dragon
 * @since 2019/11/30
 */
public class JavaVMStackOOM {

    private static int count = 0;

    private void dontStop() {
        while (true) {

        }
    }

    public  void stackLeakByThread() {
        while (true) {
            Thread thread = new Thread(() -> {
                dontStop();
            });
            System.out.println("count:" + ++count);
            thread.start();
        }
    }

    public static void main(String[] args) {
        JavaVMStackOOM javaVMStackOOM = new JavaVMStackOOM();
        javaVMStackOOM.stackLeakByThread();

    }
}
